import { Column, Entity, Index, OneToMany, OneToOne } from 'typeorm';
import { CommonEntity, CommonStatus } from '~/common/entity/common.entity';
import { ApiProperty } from '@nestjs/swagger';
import { ArticleContentEntity } from '../article/article-content/article-content.entity';
import { KnowledgeEntity } from '../knowledge/knowledge.entity';

@Entity({ name: 'ah_category' })
@Index(['id'])
export class CategoryEntity extends CommonEntity {
  @ApiProperty({ description: '分类名称' })
  @Column({ type: 'varchar', length: 50, comment: '分类名称' })
  name: string;

  @ApiProperty({ description: '分类编码' })
  @Column({ type: 'varchar', length: 100, comment: '分类编码', nullable: true })
  code: string;

  @ApiProperty({ description: '分类描述' })
  @Column({ type: 'varchar', length: 200, nullable: true, comment: '分类描述' })
  description: string;

  @ApiProperty({ description: '排序值' })
  @Column({ type: 'int', default: 0, comment: '排序值', name: 'sort_order' })
  sortOrder: number;

  @ApiProperty({ description: '是否启用' })
  @Column({
    type: 'tinyint',
    width: 1,
    default: CommonStatus.YES,
    comment: '是否启用',
    name: 'is_active'
  })
  isActive: number;

  @ApiProperty({ description: '是否删除' })
  @Column({
    type: 'tinyint',
    width: 1,
    default: CommonStatus.NO,
    comment: '是否删除',
    name: 'is_deleted'
  })
  isDeleted: number;

	@OneToMany(() => ArticleContentEntity, (articleContent) => articleContent.category)
	contents: ArticleContentEntity[];

	@OneToOne(() => KnowledgeEntity, (knowledge) => knowledge.category)
	knowledge: KnowledgeEntity
}